<template>
  <!--数据同步-->
  <el-row style="height:100%">
    <page>
      <pageheader :isShow="false">
        数据同步
      </pageheader>
      <div class="page-content">
        <el-card class="box-card tag-card">
          <el-row>
            <span style="font-size:14px">选择时间：</span>
            <div class="datecheck">
              <el-date-picker
                v-model="datetimeval"
                type="datetimerange"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                class="dataSum"
              >
              </el-date-picker>
            </div>
          </el-row>
          <el-row>
            <el-radio v-model="type" label="case">案场数据</el-radio>
            <el-radio v-model="type" label="area">区域数据</el-radio>
          </el-row>
          <el-row>
            <el-button type="primary"
                       size="small"
                       @click="syncData"
                       style="margin-left: 20px">
              同步
            </el-button>
          </el-row>
        </el-card>
      </div>
    </page>
  </el-row>
</template>
<style lang="scss">
  .page-content {
    .tag-card{
      >.el-card__body{
        >.el-row{
          margin: 20px 0;
        }
      }
    }
    padding: 15px;
    .fr {
      float: right;
    }
    .el-table {
      margin-bottom: 10px;
    }
    .paging {
      margin: 15px;
      height: 28px;
    }
    .tag-search{
      width: 40%;
      display: inline-block;
    }
    .tag-search .search-input{
      width: 300px;
      display: inline-block;
    }
    .tag-search .tag-name{
      font-size: 14px;
    }
    .datecheck {
      >span{
        font-size: 14px;
      }
      .el-input__inner {
        line-height: 36px;
        height: 36px;
        font-size: 14px;
        border-radius: 0;

        border-color: #e3eaf4;
        .el-input__icon {
          height: 36px;
          line-height: 36px;
          &.el-range__close-icon {
            display: none;
          }
        }
        .el-range-separator {
          height: 36px;
          line-height: 36px;
          padding: 0;
          width:6%;
        }
      }
      height: 36px;
      display: inline-block;
      .el-date-editor--date {
        .el-input__inner {
          border-radius: 0;
          border-color: #e3eaf4;
          height: 36px;
          line-height: 36px;
        }
        span,
        i {
          line-height: 36px;
        }
      }
      .timefast{
        width: 120px;
        .el-input__inner {
          padding: 0 20px;
          font-size: 14px;
          margin-left: -6px;
        }
      }
      .el-input--suffix {
        width: 120px;
        .el-input__inner {
          padding-right: 0;
          width: 120px;
        }
        .el-input__prefix {
          .el-input__icon {
            line-height: 36px;
            height: 36px;
          }
        }
        .el-input__suffix {
          line-height: 45px;
          vertical-align: middle;
          .el-input__suffix-inner{
            .el-icon-arrow-up.is-reverse{
              margin-top: -2px;
              display: block;
            }
          }
        }
      }
    }
  }

</style>
<script>
  let moment = require("moment");
  import page from "@/components/page/page";
  import pageheader from "@/components/page/pageheader";
  export default {
    data() {
      return {
        datetimeval:[moment(new Date()).format("YYYY-MM-DD"),moment(new Date()).format("YYYY-MM-DD")],     //日期时间
        pageTitle: "数据同步",
        type:'case',//数据类型
      }
    },
    inject: ["reload"],
    components: {
      page,
      pageheader,
    },
    created() {
      this.$Bus.$emit('Loading',false);
    },
    mounted() {
    },
    methods: {
      //配置按钮权限，根据权限不同调整表头渲染参数
      configPermissions(val){
        let buttonPermissions = val
        let menuButtonPermissions = [];//按钮权限数组
        buttonPermissions.forEach(e =>{
          for(let key in e){
            if(key == 'menu_code'){
              menuButtonPermissions.push(e[key])
            }
          }
        });
        this.buttonPermissions.isSaleData = menuButtonPermissions.includes('isSaleData') ? true : false;
        this.buttonPermissions.isFaceData = menuButtonPermissions.includes('isFaceData') ? true : false;
        this.buttonPermissions.isFlowData = menuButtonPermissions.includes('isFlowData') ? true : false;
      },
      //同步数据
      syncData(){
        this.$Bus.$emit('Loading',true);
        let url = '/predb/syn_predb_data?begin_day='+ this.datetimeval[0] +
          '&end_day=' + this.datetimeval[1] + '&type='+ this.type
        this.$api.get(url)
        .then(data=>{
          if(data.msg === 'success'){
            this.$message.success(data.data)
          }
          this.$Bus.$emit('Loading',false);
        })
        .catch(err=>{
          this.$Bus.$emit('Loading',false);
        })
      }
    },
    watch: {}
  }
</script>
